package com.study.web.controller.goal;


import cn.dev33.satoken.annotation.SaCheckLogin;
import com.study.common.core.controller.AppBaseController;
import com.study.common.core.domain.PageQuery;
import com.study.common.core.domain.R;
import com.study.common.core.page.TableDataInfo;
import com.study.goal.domain.bo.GoalAssignmentBo;
import com.study.goal.domain.vo.GoalAssignmentVo;
import com.study.goal.service.GoalAssignmentService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 目标派发控制器
 *
 * @author MT
 * @date 2025-09-03
 */
@Slf4j
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/assignment")
public class GoalAssignmentController extends AppBaseController {

    private final GoalAssignmentService goalAssignmentService;

    /**
     * 查询目标派发列表
     * @param bo
     * @param pageQuery
     * @return
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<GoalAssignmentVo> list(GoalAssignmentBo bo, PageQuery pageQuery) {
        return goalAssignmentService.queryPageList(bo, pageQuery);
    }

    /**
     * 添加目标派发
     * @param bo
     * @return
     */
    @SaCheckLogin
    @PostMapping("/goal/assign")
    public R<Void> addGoalAssignment(@Validated @RequestBody GoalAssignmentBo bo) {
        bo.setGuardianId(getUserId());
        return toAjax(goalAssignmentService.insertByBo(bo, true));
    }

    /**
     * 修改目标派发
     * @param bo
     * @return
     */
    @SaCheckLogin
    @PostMapping("/edit")
    public R<Void> editGoalAssignment(@Validated @RequestBody GoalAssignmentBo bo) {
        return toAjax(goalAssignmentService.updateByBo(bo));
    }

}
